(function() {
    var RestAngularWrapper, service;

    RestAngularWrapper = (function() {
        RestAngularWrapper.make = function(restAngularPromise) {
            return new RestAngularWrapper(restAngularPromise);
        };

        function RestAngularWrapper(restAngularPromise) {
            this.restAngularPromise = restAngularPromise;
            this.isSending = false;
            this.isError = false;
            if (this.errors == null) {
                this.errors = [];
            }
        }

        RestAngularWrapper.prototype.then = function(onSuccess, onFailure) {
            return this.restAngularPromise.then((function(_this) {
                return function(resultSuccess) {
                    _this.isSending = false;
                    return onSuccess(resultSuccess);
                };
            })(this), (function(_this) {
                return function(resultFailure) {
                    var error;
                    _this.isSending = false;
                    _this.isError = false;
                    error = {};
                    if (resultFailure.status === 0) {
                        error.isTimeout = true;
                    } else {
                        error.isTimeout = false;
                        error.status = resultFailure.status;
                        error.code = resultFailure.data.code;
                        error.message = resultFailure.data.message;
                    }
                    _this.errors.push(error);
                    if (onFailure != null) {
                        return onFailure(resultFailure);
                    }
                };
            })(this));
        };

        return RestAngularWrapper;

    })();

    service = angular.module("services.utils.RestAngularWrapper", ["services.utils.RestAngularWrapper"]);

    service.factory("RestAngularWrapper", [
        "$q", function($q) {
            return {
                make: function(restAngularPromise) {
                    return new RestAngularWrapper(restAngularPromise);
                },
                makeFromResultValue: function(value) {
                    var deferred;
                    deferred = $q.defer();
                    deferred.resolve(value);
                    return deferred.promise;
                }
            };
        }
    ]);

}).call(this);
